const exppress = require('express')
const route = exppress.Router()
//权限中间件
//引入校验中间件
const isLoginMiddle = require("../middleware/isLoginMiddle")
//提取数据库文件
const advModel = require("../db/model/advModel")

route.get('/advList/:pageNo/:everyNum',isLoginMiddle,async (req,res)=>{
     //
     const {
        pageNo,
        everyNum
     }=req.params
  //查询书库信息
    try{
        const findResult = await advModel.find({}).limit(everyNum).skip((pageNo - 1) * 3)
        const allAdvCount = await advModel.count({})//9
        // console.log(allAdvCount);
        // const allAdvCount = await advModel.count({})

        res.send({
            code:10000,
            msg:'查询成功',
            data:{
                findResult,
                pageCount: Math.ceil(allAdvCount / everyNum)
            }

            
        })
    }catch(e){
        console.log('查询广告异常'+e.message);
        res.send({
            code:10001,
            msg:'查询广告列表失败'+e.message,
            data:null
        })
    }
  
})
module.exports = route